package org.jeecg.service.service;

import org.jeecg.domain.User;
import org.jeecg.mapper.UserMapper;
import org.jeecg.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User loginUser(User user) throws Exception{
        String username = user.getUsername();
        User getuser = userMapper.getUser(username);
        if (getuser == null || !getuser.getPassword().equals(user.getPassword())){
            throw new Exception("用户名或密码错误");
        }
        return getuser;



    }

    @Override
    public User queryByUsername(String username) {
        return userMapper.selectUser(username);
    }

    @Override
    public Boolean updatePasswordByUsername(String username, String password) {
        if (username != null && password != null){
            Integer result = userMapper.updateUserPassword(username, password);
            if (result > 0){
                return true;
            }
        }
        return false;
    }

    @Override
    public Boolean updateUser(User user) {
        Integer result = userMapper.updateUserInfor(user);
        if (result > 0){
            return true;
        }
        return false;
    }
}
